/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
 * Description: Parser rbsp infomation from data
 * Author: HiMobileCam middleware develop team
 * Create: 2017-12-22
 */

#include "ffrbspparser.h"

/* T-REC-H.265-201504-I!!PDF-E.pdf
  7.4.2.3 Encapsulation of an SODB within an RBSP (informative)
*/
HI_VOID GenSodpByRbsp(const HI_U8 *src, HI_U32 srcLen, HI_U8 *dst)
{
    if ((src == HI_NULL) || (dst == HI_NULL)) {
        return;
    }
    HI_U32 numBytesInRbsp = 0;
    for (HI_U32 i = 0; i < srcLen; i++) {
        if ((i + 2 < srcLen) && (src[i] == 0x00) &&
            (src[i + 1] == 0x00) && (src[i + 2] == 0x03)) {
            dst[numBytesInRbsp++] = src[i];
            dst[numBytesInRbsp++] = src[i + 1];
            i += 2;
        } else {
            dst[numBytesInRbsp++] = src[i];
        }
    }
}
